﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/MyLayout.cshtml";
}

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link href="~/Content/bootstrap/css/style.css" rel="stylesheet" />
<link href="~/Content/bootstrap/css/base.css" rel="stylesheet" />
<script src="~/Scripts/jquery-2.1.1.min.js"></script>
<link href="~/Scripts/datejs/datecss.css" rel="stylesheet" />
<script src="~/Scripts/layer/layer.js"></script>
<script src="~/Scripts/Common.js"></script>
<script src="~/Scripts/layPage/laypage.js"></script>
<script src="~/Scripts/datejs/jquery-ui-1.10.4.custom.min.js"></script>
<script src="~/Scripts/datejs/jquery-ui-timepicker-addon.js"></script>
<link href="~/Scripts/css/gloabcss.css" rel="stylesheet" />
<style>
    input {
        width: 12%;
        height: 25px;
        margin-left: 15px;
    }

    .span8 input {
        width: 30%;
    }

    .container-fluid {
        margin: 0;
        padding: 0;
    }

    #edit_agency p {
        padding-top: 15px;
    }

    table tr td {
        padding: 12px 0px 12px 0px;
    }

    #Paging {
        position: absolute;
        float: right;
        left: 60%;
        margin-top: 4%;
    }


    /*/*/
    #div_cr_box span {
        text-align: right;
    }

    .box_cen {
        float: left;
        width: 85%;
    }

    .uploadify {
        float: left;
        margin-left: 15px;
    }

    .uploadify-button {
        background: #00AAEE;
        border-radius: 0px;
        border: 2px solid #00AAEE;
        font-size: 14px;
        color: #FFF;
        cursor: pointer;
    }

        .uploadify-button:hover {
            background: #00AAEE;
            border-radius: 0px;
            border: 2px solid #00AAEE;
            font-size: 14px;
            color: #FFF;
            cursor: pointer;
        }

    .uploadify:hover .uploadify-button {
        background: #00AAEE;
        border-radius: 0px;
        border: 2px solid #00AAEE;
        font-size: 14px;
        color: #FFF;
        cursor: pointer;
    }

    .file_input {
        width: 19.3%;
        border: 1px solid #c1c1c1;
        height: 25px;
        font-size: 14px;
        color: #4d4d4d;
        padding-left: 10px;
        line-height: 25px;
        width: 98%;
    }
</style>
<script>
    var hiden_type = 1;
    //窗体加载
    $(function () {
        hiden_type = $("#hiden_type").val();
        if (hiden_type != 1) {
            $("#btn_opea,#btn_add,#btn_Export,#div_daoru").remove();
        }
        SearchList();
        GetCateAndLev();
        $("input[name='start_time']").datetimepicker();
    });
    //查询出要编辑的人的信息
    function GetShenqing(id) {
        $.ajax({
            type: "GET",
            url: "/ShenQing/GetShenqing",
            data: { "id": id },
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.MessageCode == "0") {
                    $("#txt_name").val(data.model.name);
                    $("#txt_companyName").val(data.model.company_name);
                    $("#txt_contract_name").val(data.model.contract_name);
                    $("#txt_mobile").val(data.model.mobile);
                    $("#txt_qqCode").val(data.model.qq);
                    $("#txt_wxopen").val(data.model.wx_openid);
                    $("#txt_wwCode").val(data.model.ww_code);
                    $("#txt_idcard").val(data.model.id_card);
                    $("#txt_shopurl").val(data.model.shop_url);
                    $("#sel_Category").val(data.model.category_id);
                    $("#sel_Level").val(data.model.level_id);
                }
            }
        });
    }
    //下拉框信息
    function GetCateAndLev() {
        $("#sel_Category").html("<option value=\"-1\" code=\"0\">请选择</option>");
        $("#sel_Level").html("<option value=\"-1\" code=\"0\">请选择</option>");
        $.ajax({
            type: "GET",
            url: "/ShenQing/GetCateAndLev",
            dataType: "json",
            data: {},
            success: function (data) {
                if (data.list != "") {
                    $.each(data.Catelist, function (i, n) {
                        $("#sel_Category").append("<option value='" + n.id + "'>" + n.name + "</option>");
                    });
                    $.each(data.Levlist, function (i, n) {
                        $("#sel_Level").append("<option value='" + n.id + "' coding=\"" + n.coding + "\">" + n.name + "</option>");
                    });
                }
            }
        });
    };
    //逻辑删除
    function del(obj, id) {
        layer.open({
            type: 1,
            btn: ['确定', '取消'],
            title: '删除',
            skin: "layui-layer-molv",
            area: ['200px', '135px'],
            shade: 0.3,
            content: "你确定要删除吗",
            btn1: function () {
                $.ajax({
                    type: "POST",
                    url: "/ShenQing/delete",
                    dataType: "json",
                    data: { "id": id },
                    success: function (data) {
                        // layer.alert(JSON.stringify(data));
                        if (data.MessageCode == "0") {
                            layer.msg("删除成功！");
                            setTimeout(function () {
                                window.location.reload();
                            }, 2000)
                        } else {
                            layer.msg("删除失败！");
                        }
                    }
                });
            },
            btn2: function () {
                layer.close();
            }
        });
    }
    

    //添加和修改
    function opeation(obj, id,opea) {
        var msg = "用户申请信息"
            GetShenqing(id);
        
        layer.open({
            type: 1,
            btn: ['确定', '取消'],
            title: '' + msg + '',
            skin: "layui-layer-molv",
            area: ['600px', '630px'],
            shade: 0.3,
            content: $('#add_agency'),
            btn1: function () {
                if (CheckInputNullAll("add_agency")) {

                    var chk_lenth = $("input[name='l_shouquan']:checked").length;
                    if (chk_lenth <= 0) {
                        layer.msg("请选择是否授权！");
                        return false;
                    }
                    var chk_sh_lenth = $("input[name='l_shenhe']:checked").length;
                    if (chk_sh_lenth <= 0) {
                        layer.msg("请选择是否审核！");
                        return false;
                    }
                    var txt_name = $("#txt_name").val();
                    var txt_companyName = $("#txt_companyName").val();
                    var txt_contract_name = $("#txt_contract_name").val();
                    var txt_mobile = $("#txt_mobile").val();
                    var txt_qqCode = $("#txt_qqCode").val();
                    var txt_wxopen = $("#txt_wxopen").val();
                    var txt_wwCode = $("#txt_wwCode").val();
                    var txt_idcard = $("#txt_idcard").val();
                    var txt_shopurl = $("#txt_shopurl").val();
                    var txt_start_time = $("#txt_start_time").val();
                    var sel_Category = $("#sel_Category").val();
                    var sel_Level = $("#sel_Level").val();
                    var level_name = $('#sel_Level').find("option:selected").text();
                    var state = $("input[name='l_shouquan']:checked").val();
                    var shState = $("input[name='l_shenhe']:checked").val();
                    var coding = $('#sel_Level').find("option:selected").attr("coding")
                    if (sel_Level == -1 || sel_Level == "") {
                        layer.msg("请选择客户级别！");
                        return false;
                    }
                    if (sel_Category == -1 || sel_Category == "") {
                        layer.msg("请选择客户类别！");
                        return false;
                    }
                    $.ajax({
                        type: "POST",
                        url: "/ShenQing/OpeaShenQing",
                        dataType: "json",
                        data: {
                            "opea": opea, "id":id,"agid": 0, "Name": txt_name, "companyName": txt_companyName, "contract_name": txt_contract_name, "mobile": txt_mobile, "qq": txt_qqCode, "wxOpenid": txt_wxopen, "wwCode": txt_wwCode, "idCard":
    txt_idcard, "shopUrl": txt_shopurl, "category_id": sel_Category, "level_id": sel_Level, "level_name": level_name, "start_time": txt_start_time, "state": state, "coding": coding, "shState": shState
                        },
                        success: function (data) {
                            if (data.MessageCode == "0") {
                                layer.msg("操作成功!");
                                setTimeout(function () {
                                    SearchList();
                                }, 2000)
                            } else if (data.MessageCode == "50") {
                                layer.msg("信息存在重复!");
                            } else {
                                layer.msg("操作失败!");
                            }
                        }
                    });
                }
            },
            btn2: function () {
                layer.close();
            }
        })
    }
    //模糊查询
    function queryshenqing(pageindex, pagesize) {
        var pagecount;
        //var state = $('#states').val();
        $.ajax({
            type: "GET",
            url: "/ShenQing/queryshenqing",
            data: { "pageindex": pageindex, "pagesize": pagesize},
            dataType: "json",
            async: false,
            success: function (data) {
                $("#tab_product  tr:not(:first)").remove();
                // layer.alert(JSON.stringify(data));
                pagecount = data.Pagecount;
                if (data.MessageCode = "0") {
                    if (data.Agencylist != null) {
                        if (hiden_type == 1) {
                            $.each(data.Agencylist, function (i, n) {
                                var shState = n.shState == "0" ? "待审核" : n.shState == "1" ? "已审核" : "放弃";
                                if (n.state ==0) {
                                    var html = "<tr class='rep-tab-tr1 back-f9f'>" +
                                                                "<td>" + n.id + "</td>" +
                                                                "<td>" + n.name + "</td>" +
                                                                 "<td>" + n.categoryName + "</td>" +
                                                                   "<td>" + n.levelName + "</td>" +
                                                                "<td>" + n.wx_openid + "</td>" +
                                                                "<td>" + n.contract_name + "</td>" +
                                                                "<td>" + n.mobile + "</td>" +
                                                                 "<td>" + n.states + "</td>" +
                                                                "<td><input type='button' value='编辑' onclick='opeation(this," + n.id + ",\"add\")' style='width:30px;height:22px;margin-left:5px;cursor:pointer;border:none;color:#55AC58;'/><input type='button' value='删除'onclick='del(this," + n.id + ")' style='width:30px;height:22px; margin-left:5px;cursor:pointer;border:none;color:#55AC58;'/></td></tr>";
                                    $("#tab_product").append(html);

                                } else {
                                    var html = "<tr class='rep-tab-tr1 back-f9f'>" +
                                                              "<td>" + n.id + "</td>" +
                                                              "<td>" + n.name + "</td>" +
                                                               "<td>" + n.categoryName + "</td>" +
                                                                 "<td>" + n.levelName + "</td>" +
                                                              "<td>" + n.wx_openid + "</td>" +
                                                              "<td>" + n.contract_name + "</td>" +
                                                              "<td>" + n.mobile + "</td>" +
                                                               "<td>" + n.states + "</td>" +
                                                              "<td><input type='button' value='删除'onclick='del(this," + n.id + ")' style='width:30px;height:22px; margin-left:5px;cursor:pointer;border:none;color:#55AC58;'/></td></tr>";
                                    $("#tab_product").append(html);

                                }
                             
                            });
                        } else {

                            $.each(data.Agencylist, function (i, n) {
                                var shState = n.shState == "0" ? "待审核" : n.shState == "1" ? "已审核" : "放弃";
                                var html = "<tr class='rep-tab-tr1 back-f9f'>" +
                                                                "<td>" + n.id + "</td>" +
                                                                "<td>" + n.name + "</td>" +
                                                                "<td>" + n.categoryName + "</td>" +
                                                                   "<td>" + n.levelName + "</td>" +
                                                                "<td>" + n.wx_openid + "</td>" +
                                                                "<td>" + n.contract_name + "</td>" +
                                                                "<td>" + n.mobile + "</td>" +
                                                                 "<td>" + n.states + "</td>" +
                                                                "<td>暂无操作</tr>";
                                $("#tab_product").append(html);
                            });

                        }
                    } else {
                        layer.msg("暂无数据!");

                    }
                } else {

                    layer.msg("查询失败，请稍后再试!!");
                }
            }
        })
        return pagecount;
    }
   
    //分页
    function SearchList() {
        var pagecount = queryshenqing(1, 8);
        //好像很实用的样子，后端的同学再也不用写分页逻辑了。
        laypage({
            cont: 'pager',
            pages: pagecount, //可以叫服务端把总页数放在某一个隐藏域，再获取。假设我们获取到的是18
            skip: true, //是否开启跳页
            skin: '#5c86b2',
            curr: function () { //通过url获取当前页，也可以同上（pages）方式获取
                var page = location.search.match(/page=(\d+)/);
                return page ? page[1] : 1;
            }(),
            jump: function (e, first) { //触发分页后的回调
                if (e.pages > 1) { $('#pagercount').html('共' + e.pages + '页'); } else { $('#pagercount').hide(); }
                $('.laypage_skip').val(e.curr);
                if (!first) { //一定要加此判断，否则初始时会无限刷新
                    queryshenqing(e.curr, 8);
                }
            }
        });
    }

 

  
</script>
<input type="hidden" value="@ViewData["hiden_type"]" id="hiden_type" />
<div class="rightoverflow">
    <div class="ove-hid">
        <div class="wid-120 cor-4d4 fon-siz20 lin-hei60 bor-botdcd ">
        </div>
    </div>
    <div class="ove-hid">
        <div class="Rep-main wid-100 mag-top50">
            <div style=" margin-left: 5%;">
            </div>
            <div class="pro-div" id="con_two_1">
                <table class="rep-tab wid-100 cor-4d4 tex-ali" id="tab_product">
                    <thead>
                        <tr>
                            <td>客户编号</td>
                            <td>客户名称</td>
                            <td>类别</td>
                            <td>级别</td>
                            <td>微信号</td>
                            <td>联系人</td>
                            <td>手机</td>
                            <td>审核状态</td>
                            <td>操作</td>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>
<div id="add_agency" style="display:none;">
    <div class="divLeft"> <div class="divSpan"><span>商家名称:</span></div><div class="divInput"><input type="text" id="txt_name" placeholder="请输入商家名称" class="required" disabled="disabled" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>公司名称:</span></div><div class="divInput"><input type="text" id="txt_companyName" placeholder="请输入公司名称" class="required" disabled="disabled" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>联系人:</span></div><div class="divInput"><input type="text" id="txt_contract_name" placeholder="请输入联系人姓名" class="required" disabled="disabled" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>手机号:</span></div><div class="divInput"><input type="text" id="txt_mobile" placeholder="请输入正确的手机号" class="tel required" disabled="disabled" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>QQ号:</span></div><div class="divInput"><input type="text" id="txt_qqCode" placeholder="请输入QQ号" class="required" disabled="disabled" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>微信号:</span></div><div class="divInput"><input type="text" id="txt_wxopen" placeholder="请输入微信号" class="required" disabled="disabled" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>旺旺号:</span></div><div class="divInput"><input type="text" id="txt_wwCode" placeholder="请输入旺旺号" class="required" disabled="disabled" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>身份证号:</span></div><div class="divInput"><input type="text" id="txt_idcard" placeholder="请输入正确身份证号" class="sfz" disabled="disabled" /></div></div>
    <div class="divLeft"> <div class="divSpan"><span>店铺网址:</span></div><div class="divInput"><input type="text" id="txt_shopurl" placeholder="请输入店铺网址" class="required" disabled="disabled" /></div></div>
    <div class="divLeft">
        <div class="divSpan"><span>客户级别:</span></div><div class="divInput">
                                                         <select style="margin-left: 15px;width: 85%;height: 25px;" id="sel_Level" disabled="disabled">
                                                             <option value="-1">请选择</option>
                                                         </select>
        </div>
    </div>
    <div class="divLeft">
        <div class="divSpan"><span>客户类别:</span></div><div class="divInput">
                                                         <select style="margin-left: 15px;width: 85%;height: 25px;" id="sel_Category" disabled="disabled">
                                                             <option value="-1">请选择</option>
                                                         </select>
        </div>
    </div>
    <div class="divLeft"> <div class="divSpan"><span>授权时间(始):</span></div><div class="divInput"><input type="text" name="start_time" id="txt_start_time" placeholder="请选择授权开始时间" class="required" /></div></div>

    <div class="divLeft">
        <div class="divSpan"><span>是否授权:</span></div><div class="divInput">
            <input class="huodongchk" type="radio" name="l_shouquan" id="l_sq" value="1" style="width:20px; height:20px;" /><label for="l_sq">授权</label>
            <input class="huodongchk" type="radio" name="l_shouquan" id="l_fq" value="2" style="width: 20px; height: 20px;" /><label for="l_fq">放弃</label>
        </div>
    </div>
    <div class="divLeft">
        <div class="divSpan"><span>是否审核:</span></div><div class="divInput">
            <input class="huodongchk" type="radio" name="l_shenhe" id="l_sh" value="1" style="width:20px; height:20px;" /><label for="l_sh">审核</label>
            <input class="huodongchk" type="radio" name="l_shenhe" id="l_bsh" value="2" style="width: 20px; height: 20px;" /><label for="l_bsh">不审核</label>
        </div>
    </div>
</div>

<div id="Paging">
    <span id="pagercount" style="float:left "></span>
    <div id="pager" class="pager" style="float:left">
    </div>
</div>
<input type="hidden" id="uidHidden" />
<input type="hidden" id="AgidHidden" />
<script>

</script>
